package util

import (
	"embed"
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/theme"
	"image/color"
	"log"
)

type BasicTheme struct{}

//go:embed SourceHanSansCN-Regular.otf
var fontFS embed.FS

var myFont = getFont()

func (m BasicTheme) Color(name fyne.ThemeColorName, variant fyne.ThemeVariant) color.Color {
	//if name == theme.ColorNameBackground {
	//	if variant == theme.VariantLight {
	//		return color.White
	//	}
	//	return color.Black
	//}
	//
	return theme.DefaultTheme().Color(name, variant)
}

func (m BasicTheme) Icon(name fyne.ThemeIconName) fyne.Resource {
	return theme.DefaultTheme().Icon(name)
}

func getFont() fyne.Resource {
	fontName := "SourceHanSansCN-Regular.otf"
	fileByte, err := fontFS.ReadFile(fontName)
	if err != nil {
		log.Fatal(err)
	}

	return fyne.NewStaticResource(fontName, fileByte)
}

func (m BasicTheme) Font(style fyne.TextStyle) fyne.Resource {
	return myFont
}

func (m BasicTheme) Size(name fyne.ThemeSizeName) float32 {
	switch name {
	case theme.SizeNameText:
		return 18.0
	default:
		return theme.DefaultTheme().Size(name)
	}
}
